$(function () {
  // https://www.cnblogs.com/tugenhua0707/p/7398196.html
  $('.select-box button').each((index, item) => {
    const name = $(item).attr('name');
    // console.log('name', name);
    // $(item).click(name);
    switch (name) {
      case 'setBold':
        $(item).click(setBold)
        break;
      case 'selectAll':
        $(item).click(selectAll)
        break;
      case 'selectRange':
        $(item).click(selectRange)
        break;
      case 'selectMutiple':
        $(item).click(selectMutiple)
        break;
    }
  });

  const editor = $('#editor')[0];
  function setBold() {
    const selection = getSelection();
    const range = selection.getRangeAt(0);
    if (!isSelectionEmpty(range)) {
      document.execCommand('bold', false)
    }
  }
});
